package com.company.Demo;

import java.util.*;
import java.util.concurrent.locks.Condition;

public class Demo01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i =0;i<n;i++){
            list.add(scanner.nextInt());
        }
        int order = scanner.nextInt();
        System.out.println(max(list, order));
    }

    public static long max(List<Integer> inventory,long order){
        Collections.sort(inventory);
        int n = inventory.size();
        long sum = 0;
        for(int i =n-2;i>=0;i--){
            long  x= (inventory.get(i+1)-inventory.get(i))*(n-1-i);
            if(order<x){
                long temp = inventory.get(i+1);
                int end = n-i-1;
                long flag = inventory.get(i);
                while(order!=0&&temp>flag){
                    if(order<end){
                        sum += order*temp;
                        order=0;
                    }else{
                        order-=end;
                        sum += end*temp;
                        temp--;
                    }
                }
                if(order!=0){
                    end++;
                    temp = flag;
                    while(order!=0){
                        if(order<end){
                            sum += order*temp;
                            order=0;
                        }else{
                            order-=end;
                            sum += end*temp;
                            temp--;
                        }
                    }
                }
                break;
            }else{
                order -= x;
                sum += ((inventory.get(i+1)+inventory.get(i)+1)*(x)/2);
            }
        }
        long m = inventory.get(0);
        while(order!=0){
            if(order<n){
                sum += order*m;
                order=0;
            }else{
                order-=n;
                sum += n*m;
                m--;
            }
        }
        return sum;
    }

}
